﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace NNLInterface
{
    class txtFileWrite
    {
        /// <summary>
        /// 替换掉文本文件中的批定字符
        /// </summary>
        /// <param name="fileName">文本文件名称</param>
        /// <param name="oldFileName">旧的文年字符串</param>
        /// <param name="newFileName">新的文件字符串</param>
         public static void WritefileName(string fileName, string oldFileName,string newFileName) 
        { 
            //FileStream fs = new FileStream(fileName , FileMode.OpenOrCreate, FileAccess.Write); 
            //StreamWriter sw = new StreamWriter(fs); 
            //// Write to the file using StreamWriter class 
            //sw.BaseStream.Seek(0, SeekOrigin.End); 
            //sw.WriteLine( First Line ); 
            //sw.WriteLine( Second Line); 
            //sw.Flush(); 


             StreamReader sr = new StreamReader(fileName);
             string str = sr.ReadToEnd();
             sr.Close();
             //替换文本
             str = str.Replace(oldFileName, newFileName);
             //更改保存文本
             StreamWriter sw = new StreamWriter(fileName, false);
             sw.WriteLine(str);
             sw.Close(); 
        } 
    }
}
